<?php

namespace App\Models;


class ChatRoomMember extends Model
{
    use ModelTrait;

    protected $table = 'chat_room_member';

    /**
     * The attributes that are mass assignable.
     *
     * @var array<int, string>
     */
    protected $fillable = [
        'id',
        'chat_room_id',
        'member_id',
        'is_new_to_read',
        'created_at',
        'updated_at',
    ];

    public function chat_room()
    {
        return $this->belongsTo(ChatRoom::class,'chat_room_id','id');
    }

    public function member()
    {
        return $this->belongsTo(Member::class,'member_id','id');
    }

    public function chat_room_message()
    {
        return $this->hasMany(ChatRoomMessage::class,'chat_room_id','chat_room_id');
    }

    public function chat_room_last_message()
    {
        return $this->hasMany(ChatRoomMessage::class,'chat_room_id','chat_room_id')->orderBy('created_at','DESC')->limit(1);
    }

}
